package test.y2020;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;

/**
 * Created By  醉美柳舞之众星捧月
 *
 * @author song
 * @date 2020/5/11 10:31
 */
public class May3 {
    public static void main(String[] args) {
        Integer a0 = 128; // 相当于Integer.valueOf(128)
        Integer a = Integer.valueOf(128);
        Integer b = Integer.valueOf(128);
        System.out.println(a == b); // false
        System.out.println(a0 == b); // false
        System.out.println(128 == new Integer(128)); // Integer自动拆箱,true
        Integer c = Integer.valueOf(127);
        Integer d = Integer.valueOf(127);
        System.out.println(c == d); // true

        System.out.println(128 == Integer.valueOf(128));

        String begin = "08:57";
        String end = "23:59";

        DateTime standardBeginTime = DateUtil.parse("2020-05-01 09:00:00");
        DateTime standardEndTime = DateUtil.parse("2020-05-01 18:00:00");

        DateTime parse = DateUtil.parse(String.format("2020-05-01 %s%s", begin, ":00"));
        DateTime parse1 = DateUtil.parse(String.format("2020-05-01 %s%s", end, ":00"));

        if (parse.isAfterOrEquals(standardBeginTime)) {
            long betweenDay = DateUtil.between(parse, standardBeginTime, DateUnit.MINUTE);
            Date newDate = DateUtil.offset(standardEndTime, DateField.MINUTE, (int) betweenDay);
            long result = DateUtil.between(newDate, parse1, DateUnit.MINUTE);
            System.out.println("加班分钟数：" + result);
            String hour = new BigDecimal(result).divide(new BigDecimal(60), 1, RoundingMode.HALF_UP).toString();
            System.out.println("加班小数数：" + hour);
        } else {
            long result = DateUtil.between(standardEndTime, parse1, DateUnit.MINUTE);
            System.out.println("加班分钟数：" + result);
            String hour = new BigDecimal(result).divide(new BigDecimal(60), 1, RoundingMode.HALF_UP).toString();
            System.out.println("加班小数数：" + hour);
        }
    }
}
